package com.example.backend.controller;


import com.example.backend.pojo.Result;
import com.example.backend.pojo.Review;
import com.example.backend.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/review")
public class ReviewController {

    @Autowired
    private ReviewService reviewService;

    @PostMapping ("/getallbyuserid")
    public Result<List<Review>> getallbyuserid(Integer userid){

        return Result.success(reviewService.getallbyuserid(userid));
    }
    @PostMapping ("/getallbyresid")
    public Result<List<Review>> getallbyresid(Integer resid){

        return Result.success(reviewService.getallbyresid(resid));
    }

    @PostMapping("/addreview")
    public Result addreview(@RequestBody Review review){
        reviewService.addreview(review);
        return Result.success();
    }

    @PostMapping("/reply")
    public Result reply(Integer reviewid ,String reply)
    {
        reviewService.reply(reviewid,reply);
        return Result.success();
    }
    @PostMapping("/getByid")
    public Result getByid(Integer reviewid){
        return  Result.success(reviewService.getByid(reviewid));
    }
}
